Important: I am constrained to pgAdmin 1.8.4. It's very old (2008). Using a newer version results in many errors because the database I'm talking to is old and not updated. The other team members use this version of pgAdmin. "PostgreSQL 8.3.6 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)"
Say I want to run this query for 8 different tables:
SELECT to_char(rowlastupdated, 'YYYY-MM'), count(rowlastupdated)
FROM abc.foo
WHERE
(
rowlastupdated::TIMESTAMP >= '2012-01-01 00:00:00' :: TIMESTAMP
AND (rowlastupdated::TIMESTAMP <= '2015-12-31 23:59:59' :: TIMESTAMP)
)
group by to_char(rowlastupdated, 'YYYY-MM')
;
... repeat 7 times
Rather than find/replacing every time I want to change the start date ('2012-01-01 00:00:00'
), I'd like to make it a variable. In SQL Server I'd set that date as DECLARE @startDate varchar(30); SET @startDate = '2012-01-01 00:00:00'
and use the variable in my query (with some CAST probably).
I can't figure out how to do this in pgAdmin. The PG docs say I can do:
url varchar := 'http://example.com';
but that line just errors out in pgAdmin queries:
ERROR: syntax error at or near "url"
LINE 1: url varchar := 'http://example.com';
How can I declare a string in one place and then use it in many queries in pgAdmin? I don't want to create a function because these queries are one-time use, effectively and I don't want to clutter up the database with functions that I forgot to delete.