0

Table data: sno name trans_date 1 Jon 2023-01-01 2 Sam 2023-01-02

I am trying to run a Postgresql SQL statement via psql -c. Statement looks like this

psql -c 'Select 1 from test_tab where trans_date = ''2023-01-01'' '

also same results for this statement: psql -c 'select 1 from test_tab where name = ''Jon'' '

I get results of same statememt when running in Dbeaver but in Shell terminal I get (0 rows). It seems like the issue is with single quote and I can't find any solution online. If I compare numbers it works, only issues is with characters and dates.

Trango
  • 21
  • 4
  • 1
    Try reversing the quotes, e.g. use double quotes first and the single quotes for the value of the `where` statement. – Jetchisel Jun 26 '23 at 22:41
  • 1
    Presumably executing a single constant query is not your real task. There are a bunch of ways to fix this problem, and which one works best depends on what your real task is. – jjanes Jun 26 '23 at 22:46
  • 1
    ...mind, _in general_, shell languages are not well-suited to running arbitrary SQL queries with untrusted values. Once upon a time, about 20 years ago, I wrote a command-line SQL client with proper bind variable support that wrote NUL-delimited output, accepted key/value pairs as separate argv values on input, &c; but it was property of a former employer that never released it (and is now long since out of business). – Charles Duffy Jun 26 '23 at 22:54
  • @CharlesDuffy, so after 20 years and being out of business (legally) they still own that software you wrote? – Jetchisel Jun 26 '23 at 23:14
  • @Jetchisel, I didn't retain my own copy, which is a damned shame -- I actually did get a signed letter granting the ability to relicense a bunch of things I wrote there under a trio of OSS licenses, but I'd have to actually have a copy of the code to make any use of it. – Charles Duffy Jun 27 '23 at 00:16
  • @Jetchisel, (incidentally, that former employer is where https://github.com/charles-dyfis-net/isg-state-machine-framework came from; one of the few tools developed there, and subject to that grant of permission, I was able to get my hands on after leaving) – Charles Duffy Jun 27 '23 at 00:19
  • @Jetchisel, ...but yes -- I'm in the US; there's no automatic transfer of copyright even when current ownership is unknown or nonexistent. Probably copyright is technically held by a bank the company owed money to or some other creditor; it would cost lawyer-fee money to even do the research. – Charles Duffy Jun 27 '23 at 00:22
  • Well that is a Lesson learned, I hope. would have been nice to use/see it out there. – Jetchisel Jun 27 '23 at 00:36

0 Answers0